<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>计算右侧小于当前元素的个数</title>
</head>
<body>
  <script>
    function fn(nums) {
      const counts = new Array(nums.length);
      for (let i = 0; i < nums.length; i++) {
        let count = 0;
        for (let j = i + 1; j < nums.length; j++) {
          if (nums[j] < nums[i]) {
            count++;
          }
        }
        counts[i] = count;
      }
      return counts;
    }
    console.log(fn([5, 2, 6, 1]))
  </script>
</body>
</html>